home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / ingres04.lzh / source / monitor / quit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-20  |  2.9 KB  |  163 lines

  1. # include    "monitor.h"
  2. # include    <ingres.h>
  3. # include    <aux.h>
  4. # include    <signal.h>
  5. # include    <stdlib.h>
  6. # include    <errno.h>
  7.  
  8. #ifdef sun
  9. extern int sys_nerr;
  10. extern char *sys_errlist[];
  11. #endif
  12.  
  13. /*
  14. **  QUIT INGRES
  15. **
  16. **    This routine starts the death of the other processes.  It
  17. **    then prints out the logout message, and then waits for the
  18. **    rest of the system to die.  Note, however, that no relations
  19. **    are removed; this must be done using the PURGE command.
  20. **
  21. **    Trace Flags:
  22. **        35
  23. */
  24.  
  25. /* list of fatal signals */
  26. char    *Siglist[] =
  27. {
  28.     "Signal 0",
  29.     "hangup",
  30.     "interrupt",
  31.     "quit",
  32.     "illegal instruction",
  33.     "trace trap",
  34.     "IOT",
  35.     "EMT",
  36.     "floating point exception",
  37.     "killed",
  38.     "bus error",
  39.     "segmentation violation",
  40.     "bad system call",
  41.     "broken pipe",
  42.     "alarm",
  43. };
  44.  
  45. quit()
  46. {
  47.     register int    ndx;
  48.     register int    pidptr;
  49.     register int    err;
  50.     char        buf[100];
  51.     int        status;
  52.     int        pidlist[50];
  53.     extern void    (*ExitFn)();
  54.     char        indexx[0400];
  55.     extern char    SysIdent[];
  56.  
  57. #    ifdef xMTR1
  58.     if (tTf(35, -1))
  59.         printf("entered quit\n");
  60. #    endif
  61.  
  62.     /* INTERCEPT ALL FURTHER INTERRUPTS */
  63.     signal(SIGINT, SIG_IGN);
  64.     signal(SIGQUIT, SIG_IGN);
  65.     ExitFn = exit;
  66.  
  67.     cm_close();
  68.  
  69. #    ifdef xMTR3
  70.     if (tTf(35, 2))
  71.         printf("unlinking %s\n", Qbname);
  72. #    endif
  73.  
  74.     /* REMOVE THE QUERY-BUFFER FILE */
  75.     fclose(Qryiop);
  76.     unlink(Qbname);
  77.     if (Trapfile != NULL)
  78.         fclose(Trapfile);
  79.     pidptr = 0;
  80.     err = 0;
  81.  
  82.     /* clear out the system error index table */
  83.     for (ndx = 0; ndx < 0400; ndx++)
  84.         indexx[ndx] = 0;
  85.  
  86.     /* wait for all process to terminate */
  87.     while ((ndx = wait(&status)) != -1)
  88.     {
  89. #        ifdef xMTR2
  90.         if (tTf(35, 5))
  91.             printf("quit: pid %u: %d/%d\n",
  92.                 ndx, status >> 8, status & 0177);
  93. #        endif
  94.         pidlist[pidptr++] = ndx;
  95.         if ((status & 0177) != 0)
  96.         {
  97.             printf("%d: ", ndx);
  98.             ndx = status & 0177;
  99.             if (ndx > sizeof Siglist / sizeof Siglist[0])
  100.                 printf("Abnormal Termination %d", ndx);
  101.             else
  102.                 printf("%s", Siglist[ndx]);
  103.             if ((status & 0200) != 0)
  104.                 printf(" -- Core Dumped");
  105.             printf("\n");
  106.             err++;
  107.             indexx[I1MASK - ndx]++;
  108.         }
  109.         else
  110.         {
  111.             indexx[(status >> 8) & I1MASK]++;
  112.         }
  113.     }
  114.     if (err)
  115.     {
  116.         printf("pid list:");
  117.         for (ndx = 0; ndx < pidptr; ndx++)
  118.             printf(" %u", pidlist[ndx]);
  119.         printf("\n");
  120.     }
  121.  
  122.     /* print index of system errors */
  123.     err = 0;
  124.     for (ndx = 1; ndx <= I1MASK; ndx++)
  125.     {
  126.         if (indexx[ndx] == 0)
  127.             continue;
  128.         if (ndx <= sys_nerr)
  129.         {
  130.             if (err == 0)
  131.                 printf("\nUNIX error dictionary:\n");
  132.             printf("%3d: %s\n", ndx, sys_errlist[ndx]);
  133.         }
  134.         if (err == 0)
  135.             err = ndx;
  136.     }
  137.     if (err > 0 && err <= sys_nerr)
  138.         printf("\n");
  139.  
  140.     /* PRINT LOGOUT CUE ? */
  141.     if (Nodayfile >= 0)
  142.     {
  143.         time(buf);
  144.         printf("%s logout\n%s", SysIdent, ctime(buf));
  145.         if (getuser(Usercode, buf) == 0)
  146.         {
  147.             for (ndx = 0; buf[ndx]; ndx++)
  148.                 if (buf[ndx] == ':')
  149.                     break;
  150.             buf[ndx] = 0;
  151.             printf("goodbye %s ", buf);
  152.         }
  153.         else
  154.             printf("goodbye ");
  155.         printf("-- come again\n");
  156.     }
  157. #    ifdef xMTR1
  158.     if (tTf(35, 3))
  159.         printf("quit: exit(%d)\n", err);
  160. #    endif
  161.     exit(err);
  162. }
  163.